﻿/**  版本信息模板在安装目录下，可自行修改。
* Check_Product.cs
*
* 功 能： N/A
* 类 名： Check_Product
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2022/5/14 11:18:06   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
//using Maticsoft.DBUtility;//Please add references
namespace ElectricalTest.DAL
{
    /// <summary>
    /// 数据访问类:Check_Product
    /// </summary>
    public partial class Check_Product
    {
        public Check_Product()
        { }
        #region  BasicMethod

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string part_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Check_Product");
            strSql.Append(" where part_id=@part_id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@part_id", DbType.String,2147483647)			};
            parameters[0].Value = part_id;

            return DbHelperSQLite.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ElectricalTest.Model.Check_Product model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Check_Product(");
            strSql.Append("part_id,vehicle_type,seat_loc,left_code,right_code,sbr1_code,sbr2_code,sbr3_code,is_check_dianliu,is_check_dianzu)");
            strSql.Append(" values (");
            strSql.Append("@part_id,@vehicle_type,@seat_loc,@left_code,@right_code,@sbr1_code,@sbr2_code,@sbr3_code,@is_check_dianliu,@is_check_dianzu)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@part_id", DbType.String,2147483647),
					new SQLiteParameter("@vehicle_type", DbType.String,2147483647),
					new SQLiteParameter("@seat_loc", DbType.String,2147483647),
					new SQLiteParameter("@left_code", DbType.String,2147483647),
					new SQLiteParameter("@right_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr1_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr2_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr3_code", DbType.String,2147483647),
					new SQLiteParameter("@is_check_dianliu", DbType.Boolean),
					new SQLiteParameter("@is_check_dianzu", DbType.Boolean)};
            parameters[0].Value = model.part_id;
            parameters[1].Value = model.vehicle_type;
            parameters[2].Value = model.seat_loc;
            parameters[3].Value = model.left_code;
            parameters[4].Value = model.right_code;
            parameters[5].Value = model.sbr1_code;
            parameters[6].Value = model.sbr2_code;
            parameters[7].Value = model.sbr3_code;
            parameters[8].Value = model.is_check_dianliu;
            parameters[9].Value = model.is_check_dianzu;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ElectricalTest.Model.Check_Product model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Check_Product set ");
            strSql.Append("vehicle_type=@vehicle_type,");
            strSql.Append("seat_loc=@seat_loc,");
            strSql.Append("left_code=@left_code,");
            strSql.Append("right_code=@right_code,");
            strSql.Append("sbr1_code=@sbr1_code,");
            strSql.Append("sbr2_code=@sbr2_code,");
            strSql.Append("sbr3_code=@sbr3_code,");
            strSql.Append("is_check_dianliu=@is_check_dianliu,");
            strSql.Append("is_check_dianzu=@is_check_dianzu");
            strSql.Append(" where part_id=@part_id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@vehicle_type", DbType.String,2147483647),
					new SQLiteParameter("@seat_loc", DbType.String,2147483647),
					new SQLiteParameter("@left_code", DbType.String,2147483647),
					new SQLiteParameter("@right_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr1_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr2_code", DbType.String,2147483647),
					new SQLiteParameter("@sbr3_code", DbType.String,2147483647),
					new SQLiteParameter("@is_check_dianliu", DbType.Boolean),
					new SQLiteParameter("@is_check_dianzu", DbType.Boolean),
					new SQLiteParameter("@part_id", DbType.String,2147483647)};
            parameters[0].Value = model.vehicle_type;
            parameters[1].Value = model.seat_loc;
            parameters[2].Value = model.left_code;
            parameters[3].Value = model.right_code;
            parameters[4].Value = model.sbr1_code;
            parameters[5].Value = model.sbr2_code;
            parameters[6].Value = model.sbr3_code;
            parameters[7].Value = model.is_check_dianliu;
            parameters[8].Value = model.is_check_dianzu;
            parameters[9].Value = model.part_id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string part_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Check_Product ");
            strSql.Append(" where part_id=@part_id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@part_id", DbType.String,2147483647)			};
            parameters[0].Value = part_id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string part_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Check_Product ");
            strSql.Append(" where part_id in (" + part_idlist + ")  ");
            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElectricalTest.Model.Check_Product GetModel(string part_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select part_id,vehicle_type,seat_loc,left_code,right_code,sbr1_code,sbr2_code,sbr3_code,is_check_dianliu,is_check_dianzu from Check_Product ");
            strSql.Append(" where part_id=@part_id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@part_id", DbType.String,2147483647)			};
            parameters[0].Value = part_id;

            ElectricalTest.Model.Check_Product model = new ElectricalTest.Model.Check_Product();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElectricalTest.Model.Check_Product DataRowToModel(DataRow row)
        {
            ElectricalTest.Model.Check_Product model = new ElectricalTest.Model.Check_Product();
            if (row != null)
            {
                if (row["part_id"] != null)
                {
                    model.part_id = row["part_id"].ToString();
                }
                if (row["vehicle_type"] != null)
                {
                    model.vehicle_type = row["vehicle_type"].ToString();
                }
                if (row["seat_loc"] != null)
                {
                    model.seat_loc = row["seat_loc"].ToString();
                }
                if (row["left_code"] != null)
                {
                    model.left_code = row["left_code"].ToString();
                }
                if (row["right_code"] != null)
                {
                    model.right_code = row["right_code"].ToString();
                }
                if (row["sbr1_code"] != null)
                {
                    model.sbr1_code = row["sbr1_code"].ToString();
                }
                if (row["sbr2_code"] != null)
                {
                    model.sbr2_code = row["sbr2_code"].ToString();
                }
                if (row["sbr3_code"] != null)
                {
                    model.sbr3_code = row["sbr3_code"].ToString();
                }
                if (row["is_check_dianliu"] != null && row["is_check_dianliu"].ToString() != "")
                {
                    if ((row["is_check_dianliu"].ToString() == "1") || (row["is_check_dianliu"].ToString().ToLower() == "true"))
                    {
                        model.is_check_dianliu = true;
                    }
                    else
                    {
                        model.is_check_dianliu = false;
                    }
                }
                if (row["is_check_dianzu"] != null && row["is_check_dianzu"].ToString() != "")
                {
                    if ((row["is_check_dianzu"].ToString() == "1") || (row["is_check_dianzu"].ToString().ToLower() == "true"))
                    {
                        model.is_check_dianzu = true;
                    }
                    else
                    {
                        model.is_check_dianzu = false;
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select part_id,vehicle_type,seat_loc,left_code,right_code,sbr1_code,sbr2_code,sbr3_code,is_check_dianliu,is_check_dianzu ");
            strSql.Append(" FROM Check_Product ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Check_Product ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQLite.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.part_id desc");
            }
            strSql.Append(")AS Row, T.*  from Check_Product T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "Check_Product";
            parameters[1].Value = "part_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

